import win32gui
import win32con
import win32api
import time

# def enum_windows_callback(hwnd, extra):
#     if win32gui.IsWindowVisible(hwnd):
#         title = win32gui.GetWindowText(hwnd)
#         if title:
#             print(hwnd, title)
#
# win32gui.EnumWindows(enum_windows_callback, None)
#
# exit()
# 找窗口句柄（示例用记事本）
hwnd = win32gui.FindWindow(None, "1 - SunBrowser")
if not hwnd:
    raise Exception("窗口未找到")

# 获取窗口坐标（左, 上, 右, 下）
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
point = (455, 135)  # 客户区坐标
screen_point = win32gui.ClientToScreen(hwnd, point)
print(screen_point)
# 转换成 lParam 格式
lparam = win32api.MAKELONG(455, top+90)
# 模拟点击
win32api.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lparam)
time.sleep(0.05)  # 模拟按下时间
win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, None, lparam)

exit()
# 假设点击窗口中间
x = (left + right) // 2
y = (top + bottom) // 2

# 转换成 lParam 格式
lparam = win32api.MAKELONG(x - left, y - top)

# 模拟点击
win32api.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lparam)
time.sleep(0.05)  # 模拟按下时间
win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, None, lparam)

print("点击事件已发送")
